package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


import androidx.appcompat.app.AppCompatActivity;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class fragment_MainActivity extends AppCompatActivity implements View.OnClickListener{

    Fragment fragment1,fragment2,fragment3,fragment4;

    LinearLayout layout1,layout2,layout3,layout4;

    FragmentManager fragmentManager;

    FragmentTransaction fragmentTransaction;

    ImageView imageView1,imageView2,imageView3,imageView4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_fragment_main);

        imageView1=findViewById(R.id.imageView_my_item);

        imageView2=findViewById(R.id.imageView_friend);

        imageView3=findViewById(R.id.imageView_circle);

        imageView4=findViewById(R.id.imageView_my);


        imageView1.setImageResource(R.drawable.chat);

        imageView2.setImageResource(R.drawable.phone);

        imageView3.setImageResource(R.drawable.circle);

        imageView4.setImageResource(R.drawable.friend);


        layout1=findViewById(R.id.bottomLinearLayout1);

        layout2=findViewById(R.id.bottomLinearLayout2);

        layout3=findViewById(R.id.bottomLinearLayout3);

        layout4=findViewById(R.id.bottomLinearLayout4);

        fragment1=new BlankFragment();

        fragment2=new BlankFragment2();

        fragment3=new BlankFragment3();

        fragment4=new BlankFragment4();

        fragmentManager=getSupportFragmentManager();

        fragmentTransaction=fragmentManager.beginTransaction();

        init(fragmentTransaction);

        hideAll(fragmentTransaction);

        fragmentTransaction.show(fragment1);
        fragmentTransaction.commit();

        setLayoutShow(layout1,fragment1);
        setLayoutShow(layout2,fragment2);
        setLayoutShow(layout3,fragment3);
        setLayoutShow(layout4,fragment4);

    }

    public void hideAll(FragmentTransaction fragmentTransaction){
        fragmentTransaction.hide(fragment1);
        fragmentTransaction.hide(fragment2);
        fragmentTransaction.hide(fragment3);
        fragmentTransaction.hide(fragment4);
    }

    public void init(FragmentTransaction fragmentTransaction){
        fragmentTransaction.add(R.id.framelayout,fragment1);
        fragmentTransaction.add(R.id.framelayout,fragment2);
        fragmentTransaction.add(R.id.framelayout,fragment3);
        fragmentTransaction.add(R.id.framelayout,fragment4);
    }

    public void setLayoutShow(LinearLayout layout,Fragment fragment){
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentTransaction=fragmentManager.beginTransaction();
                hideAll(fragmentTransaction);
                fragmentTransaction.show(fragment);
                fragmentTransaction.commit();
            }
        });

    }

    @Override
    public void onClick(View view) {
//        switch (view.getId()){
//
//            case R.id.:
//        }
    }
}